package com.cqupt.medical.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 *<p>@author Jay</p>
 * <p>@date 2020/7/25 9:23</p>
 *<p> @Description: Swagger2 UI访问地址：http://localhost:80/swagger-ui.html </p>
 */

@Configuration
public class SwaggerConfigurer {


    @Value("${swagger.enable}")
    private boolean enable;


    @Value("${swagger.host}")
    private String swaggerHost;


    /**
     * 注入docket（swagger-ui）
     */
    @Bean
    public Docket docket(){

        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("医院诊疗系统")
                .description("医院诊疗系统API")
                .version("0.1")
                .contact(new Contact("蒙杰", "http://120.25.127.45:8080", "jaymengwork@163.com"))
                .build();


        return new Docket(DocumentationType.SWAGGER_2)
                .host(swaggerHost)  //指定路径当前机器ip，动静分离，跨域需要设置。
                .enable(enable)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.cqupt.medical.controller"))//扫描
                .paths(PathSelectors.any())
                .build();
    }
}
